package com.click.app.model;

import com.click.app.Functions;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @author Joel Chuca Condo
 * @date 07/04/2009
 */
@Entity
@Table(name = "laundry_request_Items")
public class LaundryRequestItem extends BaseObject {

    private Long id;
    private LaundryRequest laundryRequest;
    private LaundryType laundryType;
    private Integer quantity;
    private Double unitTotalPrice;
    private Double totalPrice;
    private Integer failQuantity;
    private Double failUnitPrice;
    private Double failTotalPrice;
    private List<LaundryItem> laundryItems = new ArrayList<LaundryItem>();
    private TradeMark tradeMark;
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id_laundry_request_item")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_trademark", nullable = false)
    public TradeMark getTradeMark() {
        return tradeMark;
    }

    public void setTradeMark(TradeMark tradeMark) {
        this.tradeMark = tradeMark;
    }
    
    @ManyToOne(fetch = FetchType.LAZY )
    @JoinColumn(name = "id_laundry_request", nullable = false)
    public LaundryRequest getLaundryRequest() {
        return laundryRequest;
    }

    public void setLaundryRequest(LaundryRequest laundryRequest) {
        this.laundryRequest = laundryRequest;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_laundry_type", nullable = false)
    public LaundryType getLaundryType() {
        return laundryType;
    }

    public void setLaundryType(LaundryType laundryType) {
        this.laundryType = laundryType;
    }


    @Column(name = "quantity")
    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    @Column(name = "unit_total_price")
    public Double getUnitTotalPrice() {
        return Functions.getDouble3Decimal(this.unitTotalPrice);
    }

    public void setUnitTotalPrice(Double unitTotalPrice) {
        this.unitTotalPrice = Functions.getDouble3Decimal(unitTotalPrice);
    }

    @Column(name = "total_price")
    public Double getTotalPrice() {
        return Functions.getDouble3Decimal(this.totalPrice);
    }

    public void setTotalPrice(Double totalPrice) {
        this.totalPrice = Functions.getDouble3Decimal(totalPrice);
    }

    @Column(name = "fail_quantity")
    public Integer getFailQuantity() {
        return failQuantity;
    }

    public void setFailQuantity(Integer failQuantity) {
        this.failQuantity = failQuantity;
    }

    @Column(name = "fail_total_price")
    public Double getFailTotalPrice() {
        return Functions.getDouble3Decimal(failTotalPrice);
    }

    public void setFailTotalPrice(Double failTotalPrice) {
        this.failTotalPrice = failTotalPrice;
    }

    @Column(name = "fail_unit_price")
    public Double getFailUnitPrice() {
        return Functions.getDouble3Decimal(failUnitPrice);
    }

    public void setFailUnitPrice(Double failUnitPrice) {
        this.failUnitPrice = Functions.getDouble3Decimal(failUnitPrice);
    }


    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "laundryRequestItem")
    public List<LaundryItem> getLaundryItems() {
        return laundryItems;
    }

    public void setLaundryItems(List<LaundryItem> laundryItems) {
        this.laundryItems = laundryItems;
    }

    @Transient
    public Double getRealPrice(){
        return totalPrice-failTotalPrice;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    } 
    

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LaundryRequestItem)) {
            return false;
        }
        LaundryRequestItem other = (LaundryRequestItem) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.click.app.model.LaundryRequestItem[id=" + id + ", quantity="+quantity+"]";
    }
}
